package com.weiaibenpao.demo.chislim.ui.fragment;


import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.weiaibenpao.demo.chislim.R;
import com.weiaibenpao.demo.chislim.base.BaseFragment;
import com.weiaibenpao.demo.chislim.bean.UserSportsInfoBean;
import com.weiaibenpao.demo.chislim.db.preferences.LocationPreferences;
import com.weiaibenpao.demo.chislim.db.preferences.UserPreferences;
import com.weiaibenpao.demo.chislim.presenter.NormalRunFPresenter;
import com.weiaibenpao.demo.chislim.ui.activity.running.StartRunActivity;
import com.weiaibenpao.demo.chislim.utils.Utils;
import com.weiaibenpao.demo.chislim.view.NormalRunFView;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * A simple {@link Fragment} subclass.
 */
public class NormalRunFragment extends BaseFragment<NormalRunFView, NormalRunFPresenter> implements NormalRunFView {


    @BindView(R.id.text_run_distance)
    TextView textRunDistance;
    @BindView(R.id.btn_start_run)
    Button btnStartRun;
    private int userId;

    public NormalRunFragment() {
        // Required empty public constructor
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_normal_run;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        userId = UserPreferences.getInstance().getInt(UserPreferences.USER_ID);
        Typeface typeFace = Typeface.createFromAsset(getContext().getAssets(), "fonts/Reducto Condensed SSi Condensed.ttf");
        textRunDistance.setTypeface(typeFace);
        mPresenter.getUserSportsInfo(userId,10,"");

    }

    @Override
    public void onResume() {
        super.onResume();
        mPresenter.getUserSportsInfo(userId,10,"");

    }



    @Override
    public void onPause() {
        super.onPause();

    }

    @OnClick(R.id.btn_start_run)
    public void onViewClicked(View view) {
        switch (view.getId()){
            case R.id.btn_start_run:
                String latitude = LocationPreferences.getInstance().getLocationLatitude();
                String longitude = LocationPreferences.getInstance().getLocationLongitude();
                StartRunActivity.openActivity(getContext(), 1, "", 0,"", 0, null,Float.parseFloat(latitude), Float.parseFloat(longitude));
                break;
        }
    }

    @Override
    public void requestSuccess(UserSportsInfoBean userSportsInfoBean) {
        double distance = userSportsInfoBean.getDjqSumSportsResult().getFinishDistance();
        textRunDistance.setText(Utils.decimalFormat(distance)+"");
    }

    @Override
    protected NormalRunFPresenter initPresenter() {
        return new NormalRunFPresenter();
    }
}
